import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 一级路由
    {
      path: '/',
      name: 'Layout',
      component: () => import('@/views/layout.vue'),
      // 子级路由
      children: [
        // 首页
        {
          path: '/',
          name: 'Home',
          component: () => import('@/views/home/index.vue'),
          meta: {
            title: '品牌、品质',
            isLogin: false,
            isMainNav: true,
            isHeader: true
          }
        },

        // 登录
        {
          path: '/login',
          name: 'Login',
          component: () => import('@/views/login/index.vue'),
          meta: {
            title: '登录',
            isLogin: false,
          }
        },

        // 注册
        {
          path: '/register',
          name: 'Register',
          component: () => import('@/views/register/index.vue'),
          meta: {
            title: '注册',
            isLogin: false,
          }
        },

        // 忘记密码
        {
          path: '/forgot-password',
          name: 'ForgotPassword',
          component: () => import('@/views/forgot-password/index.vue'),
          meta: {
            title: '忘记密码',
            isLogin: false,
          }
        },

        // 商品列表
        {
          path: '/goods-list',
          name: 'GoodsList',
          component: () => import('@/views/goods-list/index.vue'),
          meta: {
            title:'商品列表',
            isLogin: false,
            isHeader: true
          }
        },

        // 商品详情
        {
          path: '/goods-detail',
          name: 'GoodsDetail',
          component: () => import('@/views/goods-detail/index.vue'),
          meta: {
            title:'商品详情',
            isLogin: true,
            isHeader: true,
            isMainNav: true
          }
        },

        // 我的
        {
          path: '/me',
          name: 'MeLayout',
          component: () => import('@/views/me/layout.vue'),
          children: [
            // 用户中心
            {
              path: '/me',
              name: 'Me',
              component: () => import('@/views/me/home/index.vue'),
              meta:{
                title:'用户中心',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 消息通知
            {
              path: '/user/notification',
              name: 'Notification',
              component: () => import('@/views/me/notification/index.vue'),
              meta:{
                title:'消息通知',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 个人信息
            {
              path: '/user/info',
              name: 'Info',
              component: () => import('@/views/me/info/index.vue'),
              meta:{
                title:'个人信息',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 安全设置
            {
              path: '/user/set',
              name: 'Set',
              component: () => import('@/views/me/set/index.vue'),
              meta:{
                title:'安全设置',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 收货地址
            {
              path: '/user/address',
              name: 'Address',
              component: () => import('@/views/me/address/index.vue'),
              meta:{
                title:'收货地址',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },


            // 我的积分
            {
              path: '/user/integral',
              name: 'Integral',
              component: () => import('@/views/me/integral/index.vue'),
              meta:{
                title:'我的积分',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 我的足迹
            {
              path: '/user/footprint',
              name: 'Footprint',
              component: () => import('@/views/me/footprint/index.vue'),
              meta:{
                title:'我的足迹',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 收藏的商品
            {
              path: '/user/collect-goods',
              name: 'CollectGoods',
              component: () => import('@/views/me/collect-goods/index.vue'),
              meta:{
                title:'收藏的商品',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 收藏的专题
            {
              path: '/user/special-topic',
              name: 'SpecialTopic',
              component: () => import('@/views/me/special-topic/index.vue'),
              meta:{
                title:'收藏的专题',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 关注的品牌
            {
              path: '/user/follow-brand',
              name: 'FollowBrand',
              component: () => import('@/views/me/follow-brand/index.vue'),
              meta:{
                title:'关注的品牌',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 关注的商品
            {
              path: '/user/follow-goods',
              name: 'FollowGoods',
              component: () => import('@/views/me/follow-goods/index.vue'),
              meta:{
                title:'关注的商品',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 我的评价
            {
              path: '/user/evaluate',
              name: 'Evaluate',
              component: () => import('@/views/me/evaluate/index.vue'),
              meta:{
                title:'关注的商品',
                isLogin: true,
                isHeader: true,
                isMainNav: true
              }
            },

            // 我的订单
            {
              path: '/user/order',
              // name: 'UserOrder',
              children: [
                {
                  path: '', 
                  component: () => import('@/views/me/order-list/index.vue'),
                  meta: {
                    title:'我的订单',
                    isLogin: true,
                    isHeader: true,
                    isMainNav: true
                  }
                },
                { 
                  path: ':id', 
                  component: () => import('@/views/me/order-detail/index.vue'),
                  meta: {
                    title:'订单详情',
                    isLogin: true,
                    isHeader: true,
                    isMainNav: true
                  }
                }
              ]
            },

            
          ]
        },

        // 购物车
        {
          path: '/cart',
          name: 'Cart',
          component: () => import('@/views/cart/index.vue'),
          meta: {
            title:'我的购物车',
            isLogin: true,
            isHeader: true,
            isMainNav: true
          }
        },

        // 确认订单
        {
          path: '/confirm-order',
          name: 'ConfirmOrder',
          component: () => import('@/views/confirm-order/index.vue'),
          meta: {
            title:'确认订单',
            isLogin: true,
            isHeader: true,
            isMainNav: true
          }
        }
      ]
    },

  ],
  // 路由滚动行为
  scrollBehavior (to, from, savedPosition) {
    return {
      top: 0
    }
  }
})

export default router
